package cn.wch.blelib.peripheral.builder;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;

import androidx.annotation.NonNull;

/**
 * Bluetooth Gatt特性生成器
 */
public class BluetoothGattCharacteristicBuilder {
    private final UUID uuid;
    private final int properties;
    private final int permissions;
    private ArrayList<BluetoothGattDescriptor> descriptorList;

    /**
     * 实例化
     * @param uuid uuid
     * @param properties 属性值（参考：{@link cn.wch.blelib.peripheral.builder.constant.CharacteristicProperty}）
     * @param permissions 权限（参考：{@link cn.wch.blelib.peripheral.builder.constant.CharacteristicPermission}）
     */
    public BluetoothGattCharacteristicBuilder(@NonNull UUID uuid, int properties, int permissions) {
        this.uuid = uuid;
        this.properties = properties;
        this.permissions = permissions;
        descriptorList=new ArrayList<>();
    }

    /**
     * 添加描述符
     * @param descriptors
     */
    public void addDescriptors(Collection<BluetoothGattDescriptor> descriptors){
        descriptorList.addAll(descriptors);
    }

    /**
     * 添加描述符
     * @param descriptor
     */
    public void addDescriptor(BluetoothGattDescriptor descriptor){
        descriptorList.add(descriptor);
    }

    /**
     * 构造函数
     * @return
     */
    public BluetoothGattCharacteristic build(){
        BluetoothGattCharacteristic characteristic=new BluetoothGattCharacteristic(uuid, properties, permissions);
        for (BluetoothGattDescriptor descriptor : descriptorList) {
            characteristic.addDescriptor(descriptor);
        }
        return characteristic;
    }
}
